<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // promise 承诺 诺言
      // pending(待定的)    fulfilled(已解决，已实现)     reject(已拒绝，没有实现)

      // let isForget = true;
      let isForget = false;
      let getLv = new Promise((resolve, reject) => {
        if (isForget) {
          let lv = {
            color: "blue",
            price: "￥9999",
          };
          resolve(lv);
        } else {
          let err = new Error("我加班了，忘记了");
          reject(err);
        }
      });
      // 基本调用
      let testFn = function () {
        getLv
          .then((fulfilled) => {
            console.log(fulfilled);
          })
          .catch((rejected) => {
            console.log(rejected.message);
          });
      };
      testFn();
      // 链式调用
    </script>
  </body>
</html>
